#include "widget.h"
#include "ui_widget.h"

#include <QDebug>
#include <QRegExpValidator>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QRegExp regExp("^1\\d{10}$");

    ui->lineEdit->setClearButtonEnabled(true);
    ui->lineEdit->setPlaceholderText("请输入姓名");

    ui->lineEdit_2->setClearButtonEnabled(true);
    ui->lineEdit_2->setPlaceholderText("请输入密码");
    ui->lineEdit_2->setEchoMode(QLineEdit::Password);

    ui->lineEdit_4->setPlaceholderText("请确认密码");
    ui->lineEdit_4->setClearButtonEnabled(true);
    ui->lineEdit_4->setEchoMode(QLineEdit::Password);

    ui->lineEdit_3->setClearButtonEnabled(true);
    ui->lineEdit_3->setPlaceholderText("请输入电话");
    ui->lineEdit_3->setValidator(new QRegExpValidator(regExp));
    ui->pushButton->setEnabled(false);

    ui->label_6->setText("密码为空");
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QString gender = ui->radioButton->isChecked() ? "人类" : "非人类";

    qDebug() << "姓名" << ui->lineEdit->text();
    qDebug() << "密码" << ui->lineEdit_2->text();
    qDebug() << "性别" << gender;
    qDebug() << "电话" << ui->lineEdit_3->text();

}

void Widget::on_lineEdit_3_textEdited(const QString &text)
{
    QString content = text;
    int pos = 0;
    if(ui->lineEdit_3->validator()->validate(content,pos) == QValidator::Acceptable)
    {
        ui->pushButton->setEnabled(true);
    }
    else
    {
        ui->pushButton->setEnabled(false);
    }
}

void Widget::on_lineEdit_2_textEdited(const QString &arg1)
{
    this->compare();
    (void)arg1;
}

void Widget::on_lineEdit_4_textEdited(const QString &arg1)
{
    this->compare();
    (void)arg1;
}

void Widget::compare()
{
    const QString &s1 = ui->lineEdit_2->text();
    const QString &s2 = ui->lineEdit_4->text();
    if(s1.isEmpty() && s2.isEmpty())
    {
        ui->label_6->setText("密码为空");
    }
    else if(s1 == s2)
    {
        ui->label_6->setText("密码一致");
    }
    else
    {
        ui->label_6->setText("密码不一致");
    }
}

void Widget::on_checkBox_stateChanged(int arg1)
{

}

void Widget::on_checkBox_toggled(bool checked)
{
    if(checked)ui->lineEdit_2->setEchoMode(QLineEdit::Normal);
    else ui->lineEdit_2->setEchoMode(QLineEdit::Password);
}

void Widget::on_checkBox_2_toggled(bool checked)
{
    if(checked)ui->lineEdit_4->setEchoMode(QLineEdit::Normal);
    else ui->lineEdit_4->setEchoMode(QLineEdit::Password);
}
